<template>
  <transition name="confirm-fade">
    <div class="confirm" v-show="showFlag" @click.stop>
      <div class="confirm-wrapper">
        <div class="confirm-content">
          <p class="text">{{text}}</p>
          <div class="operate">
            <div class="operate-btn left" @click="handleCancelClick">{{cancelBtnText}}</div>
            <div class="operate-btn" @click="handleConfirmClick">{{confirmBtnText}}</div>
          </div>
        </div>
      </div>
    </div>
  </transition>
</template>

<script>
export default {
  props: {
    text: {
      type: String,
      default: ''
    },
    cancelBtnText: {
      type: String,
      default: ''
    },
    confirmBtnText: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      showFlag: false
    }
  },
  methods: {
    show() {
      this.showFlag = true
    },
    hide() {
      this.showFlag = false
    },
    handleConfirmClick() {
      this.hide()
      this.$emit('confirm')
    },
    handleCancelClick() {
      this.hide()
      this.$emit('cancel')
    }
  }
}
</script>

<style lang="stylus" scoped>
  @import "~common/stylus/variable"
  .confirm
    position: fixed
    top: 0
    left: 0
    right: 0
    bottom: 0
    z-index: 998
    background-color: $color-background-d
    &.confirm-fade-enter-active, &.confirm-fade-leave-active
      transition: opacity .3s
    &.confirm-fade-enter, &.confirm-fade-leave-to
      opacity: 0
    .confirm-wrapper
      position: absolute
      top: 50%
      left: 50%
      transform: translate3d(-50%, -50%, 0)
      z-index: 999
      .confirm-content
        width: 270px
        border-radius: 13px
        background: $color-highlight-background
        .text
          padding: 19px 15px
          line-height: 22px
          text-align: center
          font-size: $font-size-large
          color: $color-text-l
        .operate
          display: flex
          align-items: center
          text-align: center
          font-size: $font-size-large
          .operate-btn
            flex: 1
            line-height: 22px
            padding: 10px 0
            border-top: 1px solid $color-background-d
            color: $color-text-d
            &.left
              border-right: 1px solid $color-background-d
</style>
